import store from '@/store/index.js'
let baseUrl = 'http://testapp.xuexiluxian.cn'
export default ({
	url,
	config,
	data
}) => {
	return new Promise((resolve, reject) => {
		// 添加拦截器
		uni.addInterceptor('request', {
			invoke (data) { // 请求拦截
			  if (store?.state?.user?.token) {
				 data.header = {
					 ...data.header,
					 Authorization: store.state.user.token
				 }
			  }
			  return data
			},
			success(args) { // 响应拦截
				
			}
		})
		uni.request({
			url: baseUrl + url,
			...config,
			data,
			success: (res) => {
				resolve(res.data)
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}